﻿using Microsoft.AspNetCore.Mvc;
using MinimalistFoodStreet.BackEnd.Infrastructure.Attributes;
using MinimalistFoodStreet.BackEnd.Infrastructure.Dtos.Response;
using MinimalistFoodStreet.BackEnd.Server.IServer;

namespace MinimalistFoodStreet.BackEnd.Api.Api.Controllers.Tables
{
    public class StatisticsController : BaseController
    {
        private readonly IStatisticsServer _statisticsServer;

        public StatisticsController(IStatisticsServer statisticsServer)
        {
            _statisticsServer = statisticsServer;
        }

        /// <summary>
        /// 获取管理端首页统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.administrators })]
        public async Task<IActionResult> GetAdminHomeStatistics(string timeType)
        {
            return Send(await _statisticsServer.GetAdminHomeStatistics(timeType));
        }

        /// <summary>
        /// 获取供应商端首页统计
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] { CheckLoginRoles.suppliers })]
        public async Task<IActionResult> GetSupplierHomeStatistics()
        {
            return Send(await _statisticsServer.GetSupplierHomeStatistics(_supplier.SId));
        }

        /// <summary>
        /// 获取供应商图表页统计
        /// </summary>
        /// <param name="timeType"></param>
        /// <returns></returns>
        [HttpGet]
        [CheckLogin(new CheckLoginRoles[] {CheckLoginRoles.suppliers})]
        public async Task<IActionResult> GetSupplierChartStatistics(string timeType)
        {
            return Send(await _statisticsServer.GetSupplierChartStatistics(timeType, _supplier.SId));
        }

    }
}
